package commonAdmin.sql.support;

import java.lang.reflect.Field;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

public class FieldColumnMapper {

	protected String fieldName;
	protected String columnName;
	protected Field field;

	public FieldColumnMapper(Field field) {
		this.field = field;
		this.fieldName = field.getName();
		if (field.isAnnotationPresent(Column.class)) {
			Column column = field.getAnnotation(Column.class);
			this.columnName = StringUtils.isNotBlank(column.name()) ? column.name() : this.fieldName;
		} else {
			this.columnName = fieldName;
		}
	}

	public static void main(String[] args) {
		int a = 1;
		System.err.println(int.class.isPrimitive());
		Integer b = 1;
		System.err.println(b.getClass().isPrimitive());
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public void setField(Field field) {
		this.field = field;
	}

	public Field getField() {
		return field;
	}

	/**
	 * 是否为主键id
	 * @return
	 */
	public boolean isId() {
		return field.isAnnotationPresent(Id.class) || columnName.equalsIgnoreCase("id");
	}

}